package com.future.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.future.domain.Like;
import com.future.domain.vo.LikeTargetVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Map;


@Mapper
public interface LikeMapper extends BaseMapper<Like> {
    /**
     * 查询用户总被点赞数
     * @param userId 用户ID
     * @return 总被点赞数
     */
    Long selectTotalLikesReceived(@Param("userId") Long userId);

    Page<LikeTargetVO> selectLikeArticleList(Page<LikeTargetVO> page, @Param("userId") Long userId);

    Page<LikeTargetVO> selectLikeMediaResourceList(Page<LikeTargetVO> page,@Param("userId") Long userId);

    /**
     * 查询用户是否点赞了指定目标
     * @param targetId 目标ID
     * @param userId 用户ID
     * @param targetType 目标类型
     * @return 1表示已点赞，0表示未点赞
     */
    int selectLikeOrNotByTargetIdAndType(@Param("targetId") Long targetId, @Param("userId") Long userId, @Param("targetType") String targetType);

    @Select("SELECT count(*) FROM `like` "+
            "WHERE target_id = #{targetId} " +
            "and user_id=#{userId} " +
            "and target_type=#{targetType}")
    int selectLikeOrNotByArticleId(Long articleId, Long userId);

    @Select("SELECT count(*) FROM collection " +
            "WHERE target_id = #{articleId} " +
            "and user_id=#{userId} " +
            "and target_type='文章'")
    int selectCollectOrNotByArticleId(Long articleId, Long userId);
}
